<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>判断点是否在多边形内</title>
	<link rel="stylesheet" href="css/ol.css">
	<style>
		body{
			margin: 0;
		}

		#map{
			/*width: 100vw;*/
			height: 100vh;
		}
	</style>
</head>
<body>
	<div id="map"></div>
</body>
</html>
<script src="js/ol.js"></script>
<script>
	var vector = new ol.source.Vector({
		url: "./data/china.geojson",
		format: new ol.format.GeoJSON()
	});
	var map = new ol.Map({
		layers: [
		new ol.layer.Tile({
			source: new ol.source.OSM()
		}),
		new ol.layer.Vector({
			source: vector
		})
		],
		target: 'map',
		view: new ol.View({
			center: ol.proj.transform([109.2, 37.2], "EPSG:4326", "EPSG:3857"),
			zoom: 4
		})
	});

	map.on("click", function (e) {
		var point = e.coordinate;

		// 如果point在vector的feature内，返回true;如果不在，返回false
	    var isIn = vector.getFeatures()[0].getGeometry().intersectsExtent(point);
	    console.log("点在多边形内",isIn);
	});
</script>